package pl.register.android.student;

import pl.register.android.lesson.Lesson;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Mateusz Strzelecki
 * @since 2013-04-09
 */

public class Student implements Serializable, Comparable<Student> {

    private Long id;

    private String firstName;

    private String lastName;

    private String phoneNo;

    private String emailAddress;

    private String city;

    private String classNo;

    private List<Lesson> lessons;

    public static Student nullObject() {
        return new Student(null, "", "", "", "", "", "");
    }

    public Student(Long id, String firstName, String lastName, String phoneNo, String emailAddress, String city, String classNo) {
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
        this.phoneNo = phoneNo;
        this.city = city;
        this.emailAddress = emailAddress;
        this.classNo = classNo;
        this.lessons = new ArrayList<Lesson>();
    }

    public Long getId() {
        return id;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public String getPhoneNo() {
        return phoneNo;
    }

    public String getCity() {
        return city;
    }

    public String getEmailAddress() {
        return emailAddress;
    }

    public String getClassNo() {
        return classNo;
    }

    public List<Lesson> getLessons() {
        return lessons;
    }

    public void setLessons(List<Lesson> lessons) {
        this.lessons = lessons;
    }

    public void addLesson(Lesson lesson) {
        lessons.add(lesson);
    }

    public void removeLastLesson() {
        int lastIndex = lessons.size() - 1;
        if (lastIndex >= 0) {
            lessons.remove(lastIndex);
        }
    }

    public void setId(long id) {
        this.id = id;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public void setPhoneNo(String phoneNo) {
        this.phoneNo = phoneNo;
    }

    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public void setClassNo(String classNo) {
        this.classNo = classNo;
    }

    public boolean isPersist() {
        return id != null;
    }

    @Override
    public int compareTo(Student toCompare) {
        return firstName.toLowerCase().compareTo(toCompare.getFirstName().toLowerCase());
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", firstName='" + firstName + '\'' +
                ", lastName='" + lastName + '\'' +
                ", phoneNo='" + phoneNo + '\'' +
                ", emailAddress='" + emailAddress + '\'' +
                ", classNo=" + classNo +
                '}';
    }
}